package cn.makabaka.epidemic.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cn.makabaka.epidemic.common.Result;

import cn.makabaka.epidemic.service.IComeinService;
import cn.makabaka.epidemic.entity.Comein;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 庆宝
 * @since 2022-07-07
 */
@RestController
@RequestMapping("//comein")
public class ComeinController {

    @Resource
    private IComeinService comeinService;

    // 新增或者更新
    @PostMapping
    public Result save(@RequestBody Comein comein) {
        comeinService.saveOrUpdate(comein);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        comeinService.removeById(id);
        return Result.success();
    }

    @PostMapping("/del/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        comeinService.removeByIds(ids);
        return Result.success();
    }

    @GetMapping
    public Result findAll() {
        return Result.success(comeinService.list());
    }

    @GetMapping("/{id}")
    public Result findOne(@PathVariable Integer id) {
        return Result.success(comeinService.getById(id));
    }

    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                           @RequestParam Integer pageSize) {
        QueryWrapper<Comein> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return Result.success(comeinService.page(new Page<>(pageNum, pageSize), queryWrapper));
    }

}

